/*++

Copyright (c) 2007  Microsoft Corporation 

Filename: 

    CreateTables.cs 

Abstract: 

    A class that create tables to store network names, ip address, disk parameters
     
--*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Globalization; 

namespace NRTMAddIn
{
    class CreateTables
    {
        #region Private Variables
         
        //Dataset variable 
        private DataSet _dsMonitor;
        //Datatable variable to machine details
        private DataTable _dtMachines;
        //Datatable variable to store disk details
        private DataTable _dtDiskDetails;

        //DataSet and Datatable names
        private const string dsNRTMDatabase  = "NRTMDatabase";
        private const string dtMachines      = "Machines";
        private const string dtDiskDetails   = "DiskDetails";

        //Column names of Datatables
        private const string ServerName      = "ServerName"; 
        private const string IPAddress       = "IPAddress";
        private const string DiskName        = "DiskName";
        private const string TotalSizeMB     = "TotalSizeMB";
        private const string FreeSpaceMB     = "FreeSpaceMB";
        private const string FileSystem      = "FileSystem";
        private const string Description     = "Description" ;
        private const string PerFreeSpace    = "PerFreeSpace";
        private const string DiskState       = "DiskState";

        #endregion

        #region Properties

        //Get & Set Monitor dataset values
        public DataSet DsMonitor
        {
            get
            {
                return _dsMonitor;
            }
            set
            {
                _dsMonitor = value;
            }
        }

        //Get & Set Machine datatable values
        public DataTable DtMachines
        {
            get
            {
                return _dtMachines;
            }
            set
            {
                _dtMachines = value;
            }
        }

        //Get & Set DiskDetails datatable values
        public DataTable DtDiskDetails
        {
            get
            {
                return _dtDiskDetails;
            }
            set
            {
                _dtDiskDetails = value;
            }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Default Constructor.
        /// </summary>
        public CreateTables()
        {
            AddTables();
        }
        #endregion

        #region Methods
        /// <summary>
        /// Create dataset and add data tables for storing monitoring data
        /// </summary>
        private void AddTables()
        {
            try
            {
                //Create a new dataset
                DsMonitor = new DataSet(dsNRTMDatabase);
                DsMonitor.Locale = CultureInfo.InvariantCulture;

                //Add machines table to dataset
                DtMachines = DsMonitor.Tables.Add(dtMachines);
                DtMachines.Columns.Add(ServerName);
                DtMachines.Columns.Add(IPAddress);
                
                //Add disk details table to dataset
                DtDiskDetails = DsMonitor.Tables.Add(dtDiskDetails);
                DtDiskDetails.Columns.Add(ServerName, Type.GetType("System.String"));
                DtDiskDetails.Columns.Add(DiskName, Type.GetType("System.String"));
                DtDiskDetails.Columns.Add(TotalSizeMB, Type.GetType("System.Int32"));
                DtDiskDetails.Columns.Add(FreeSpaceMB, Type.GetType("System.Int32"));
                DtDiskDetails.Columns.Add(FileSystem, Type.GetType("System.String"));
                DtDiskDetails.Columns.Add(Description, Type.GetType("System.String"));
                DtDiskDetails.Columns.Add(PerFreeSpace, Type.GetType("System.Int32"));
                DtDiskDetails.Columns.Add(DiskState, Type.GetType("System.String"));
            }
            catch(Exception ex)
            {
                //Throw user-defined exception
                throw new NrtmException("Create data tables", ex);
            }
        }
        #endregion
    }
}
